package com.linkage.educloud.ah.bean;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by Mr'Tang on 2018/12/18.
 */

public class SubjectBean implements Serializable {
    private int id;
    private String name;

    public static List<SubjectBean> fromJSONObject(JSONObject json) {
        List<SubjectBean> subjectList = new ArrayList<>();
        if (json.has("subjects")) {
            try {
                JSONArray jar = json.getJSONArray("subjects");
                for (int i = 0; i < jar.length(); i++) {
                    JSONObject obj = jar.getJSONObject(i);
                    SubjectBean subject = new SubjectBean();
                    subject.id = obj.optInt("id");
                    subject.name = obj.optString("name");
                    subjectList.add(subject);
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
        return subjectList;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}
